package com.zd.bms.service.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zd.bms.bean.vo.ScenicSpotDetailVo;
import com.zd.bms.bean.vo.TicketOrderDetailVo;
import com.zd.bms.bean.vo.req.OrderListReqVo;
import com.zd.bms.bean.vo.req.UserIdInfoReqVo;
import com.zd.bms.bean.vo.resp.TicketOrderDetailRespVo;
import com.zd.bms.service.IScenicSpotService;
import com.zd.bms.service.ITicketOrderService;
import com.zd.common.bean.model.BmsUser;
import com.zd.common.bean.model.ShortQrcode;
import com.zd.common.bean.model.TicketInfo;
import com.zd.common.bean.model.TicketOrder;
import com.zd.common.bean.model.TicketOrderDetail;
import com.zd.common.common.enums.BmsUserTypeEnum;
import com.zd.common.common.enums.PayStatusEnum;
import com.zd.common.common.enums.PayTypeEnum;
import com.zd.common.common.enums.PrintStatusEnum;
import com.zd.common.common.enums.TicketChannelEnum;
import com.zd.common.common.enums.TicketVerifyTypeEnum;
import com.zd.common.common.enums.UseTicketsStatusEnum;
import com.zd.common.common.enums.UserIdNumberTypeEnum;
import com.zd.common.common.utils.DateTimeUtil;
import com.zd.common.common.utils.JSONUtil;
import com.zd.common.common.utils.LogUtils;
import com.zd.common.common.utils.QrCodeCreateUtil;
import com.zd.common.common.utils.StringUtils;
import com.zd.common.dao.ShortQrcodeDao;
import com.zd.common.dao.TicketInfoDao;
import com.zd.common.dao.TicketOrderDao;
import com.zd.common.dao.TicketOrderDetailDao;
import com.zd.common.dao.common.BaseDao;
import com.zd.common.dao.common.FindRequestEntity;
import com.zd.common.dao.common.OrderEnum;
import com.zd.common.dao.common.Page;
import com.zd.common.dao.common.WhereEnum;
import com.zd.common.service.impl.BaseServiceImpl;

@Service
public class TicketOrderServiceImpl extends BaseServiceImpl<TicketOrder> implements ITicketOrderService{

	@Autowired
	private TicketOrderDao ticketOrderDao;
	
	@Autowired
	private TicketOrderDetailDao ticketOrderDetailDao;

	@Autowired
	private TicketInfoDao ticketInfoDao;
	
	@Autowired
	private IScenicSpotService scenicSpotService;
	
	@Autowired
	private ShortQrcodeDao shortQrcodeDao;
	
	@Override
	public BaseDao<TicketOrder> getBaseDao() {
		return ticketOrderDao;
	}
	
	@Override
	public Map<String, Object> getTicketOrderDetailList(String userIdNumber, String checkCode,Integer modeType,BmsUser bmsUser) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("status", false);
		FindRequestEntity findReq = new FindRequestEntity();
		if(!StringUtils.isBank(checkCode)){
			findReq.addWhere("check_code", WhereEnum.EQ, checkCode);
		}
		if(!StringUtils.isBank(userIdNumber)){
			findReq.addWhere("receiver_id_number", WhereEnum.EQ, userIdNumber);
			findReq.addWhere("scenic_spot_id", WhereEnum.EQ, bmsUser.getScenicSpotId());
			findReq.addWhere("status", WhereEnum.EQ, PayStatusEnum.Payment_success.getKey());
			List<TicketOrder> ticketOrderList = ticketOrderDao.find(findReq);
			if( ticketOrderList == null || ticketOrderList.size() == 0){
				findReq = new FindRequestEntity();
				findReq.addWhere("user_id_number", WhereEnum.EQ, userIdNumber);
				findReq.addWhere("scenic_spot_id", WhereEnum.EQ, bmsUser.getScenicSpotId());
				findReq.addWhere("status", WhereEnum.EQ, UseTicketsStatusEnum.Already_paid.getKey());
				findReq.addWhere("valid_time", WhereEnum.GT, new Date());
				if(modeType == 1){
					findReq.addWhere("print_status", WhereEnum.EQ, PrintStatusEnum.Non_Printing.getKey());
				}
				List<TicketOrderDetail> ticketOrderDetails = ticketOrderDetailDao.find(findReq);
				if(ticketOrderDetails != null && ticketOrderDetails.size() > 0){
					List<TicketOrderDetailVo> ticketOrderDetailVoList = orderDetailToVoPC(ticketOrderDetails);
					resultMap.put("ticketOrderDetailVoList",  ticketOrderDetailVoList);
					resultMap.put("status", true);
					return resultMap;
				}
				resultMap.put("msg", "没有票务信息");
				return resultMap;
			}
			List<TicketOrderDetailVo> ticketOrderDetailVoList = new ArrayList<>();
			for (TicketOrder ticketOrder : ticketOrderList) {
				if((ticketOrder.getTicketNums() - ticketOrder.getPrintNumber())>0){
					findReq = new FindRequestEntity();
					findReq.addWhere("order_id", WhereEnum.EQ, ticketOrder.getId());
					findReq.addWhere("status", WhereEnum.EQ, UseTicketsStatusEnum.Already_paid.getKey());
					findReq.addWhere("scenic_spot_id", WhereEnum.EQ, bmsUser.getScenicSpotId());
					findReq.addWhere("valid_time", WhereEnum.GT, new Date());
					if(modeType == 1){
						findReq.addWhere("print_status", WhereEnum.EQ, PrintStatusEnum.Non_Printing.getKey());
					}
					List<TicketOrderDetail> ticketOrderDetails = ticketOrderDetailDao.find(findReq);
					List<TicketOrderDetailVo> ticketOrderDetailVos = orderDetailToVoPC(ticketOrderDetails);
					ticketOrderDetailVoList.addAll(ticketOrderDetailVos);
				}
			}
			if(ticketOrderDetailVoList != null && ticketOrderDetailVoList.size() >0){
				resultMap.put("ticketOrderDetailVoList", ticketOrderDetailVoList);
				resultMap.put("status", true);
				return resultMap;
			}
			resultMap.put("msg", "没有票务信息");
			return resultMap;
		}
		LogUtils.info(userIdNumber + "         :          " + checkCode);
		findReq.addWhere("status", WhereEnum.EQ, UseTicketsStatusEnum.Already_paid.getKey());
		if(modeType == 1){
			findReq.addWhere("print_status", WhereEnum.EQ, PrintStatusEnum.Non_Printing.getKey());
		}
		List<TicketOrderDetail> ticketOrderDetails = ticketOrderDetailDao.find(findReq);
		if(ticketOrderDetails != null && ticketOrderDetails.size() > 0){
			findReq = new FindRequestEntity();
			findReq.addWhere("status", WhereEnum.EQ, UseTicketsStatusEnum.Already_paid.getKey());
			findReq.addWhere("scenic_spot_id", WhereEnum.EQ, bmsUser.getScenicSpotId());
			findReq.addWhere("valid_time", WhereEnum.GT, new Date());
			if(modeType == 1){
				findReq.addWhere("print_status", WhereEnum.EQ, PrintStatusEnum.Non_Printing.getKey());
			}
			findReq.addWhere("order_id", WhereEnum.EQ, ticketOrderDetails.get(0).getOrderId());
			List<TicketOrderDetail> ticketOrderDetailsl= ticketOrderDetailDao.find(findReq);
			List<TicketOrderDetailVo> ticketOrderDetailVoList = orderDetailToVoPC(ticketOrderDetailsl);
			resultMap.put("ticketOrderDetailVoList",  ticketOrderDetailVoList);
			resultMap.put("status", true);
			return resultMap;
		}
		resultMap.put("msg", "没有票务信息");
		return resultMap;
	}
	
	private List<TicketOrderDetailVo> orderDetailToVoPC(List<TicketOrderDetail> ticketOrderDetailList) throws Exception{
		List<TicketOrderDetailVo> ticketOrderDetailVoList = new ArrayList<>();
		if(ticketOrderDetailList != null && ticketOrderDetailList.size() > 0){
			for (TicketOrderDetail ticketOrderDetail : ticketOrderDetailList) {
				TicketOrderDetailVo ticketOrderDetailVo= new TicketOrderDetailVo();
				BeanUtils.copyProperties(ticketOrderDetail, ticketOrderDetailVo);
				
				ShortQrcode shortQrcode =new ShortQrcode();
				String uuid = StringUtils.getRandomWithTimestamp16();
				shortQrcode.setUuid(uuid);
				shortQrcode.setOrderDetailId(ticketOrderDetail.getId());
				shortQrcode.setScenicSpotId(ticketOrderDetail.getScenicSpotId());
				shortQrcode.setOrderId(ticketOrderDetail.getOrderId());
				shortQrcode.setCheckCode(ticketOrderDetail.getCheckCode());
				shortQrcodeDao.insert(shortQrcode);
				
				ticketOrderDetailVo.setQrCodeStr(shortQrcode.getUuid());
				ticketOrderDetailVo.setQrCode(QrCodeCreateUtil.generalQRCode(ticketOrderDetailVo.getQrCodeStr()));
					
				ticketOrderDetailVo.setEntryTimeStr(DateTimeUtil.date2String(ticketOrderDetail.getEntryTime()));
				ticketOrderDetailVo.setValidTimeStr(DateTimeUtil.date2String(ticketOrderDetail.getValidTime()));
				
				TicketInfo ticketInfo = ticketInfoDao.get(ticketOrderDetail.getTicketId());
				ticketOrderDetailVo.setPrices(ticketInfo.getPrice(), ticketInfo.getChildRate());
				ticketOrderDetailVo.setEffectiveNum(ticketInfo.getVerifyType());
				ticketOrderDetailVoList.add(ticketOrderDetailVo);
			}
		}
		return ticketOrderDetailVoList;
	}

	@Override
	public Map<String, Object> buyTiecktsPC(String userIdInfoList, Integer ticketInfoId, BmsUser bmsUser) throws Exception {
		List< UserIdInfoReqVo> userIdInfoVo = JSONUtil.jsonToList(userIdInfoList, UserIdInfoReqVo.class);
		TicketInfo ticketInfo = ticketInfoDao.get(ticketInfoId);
		ScenicSpotDetailVo scenicSpotDetailVo = scenicSpotService.getScenicSpotDetail(ticketInfo.getScenicSpotId());
		TicketOrder ticketOrder = new TicketOrder();
		ticketOrder.setScenicSpotId(scenicSpotDetailVo.getId());
		ticketOrder.setChannel(TicketChannelEnum.Scenic_spot_conductor.getKey());
		ticketOrder.setUserId(bmsUser.getId());
		ticketOrder.setTicketId(ticketInfo.getId());
		Integer totalfee = 0;
		Integer ticketNum = 0;
		for (UserIdInfoReqVo userIdInfoReqVo : userIdInfoVo) {
			ticketNum = ticketNum +  userIdInfoReqVo.getChildNums();
			Integer fee =(int) (ticketInfo.getPrice() + ticketInfo.getPrice()*ticketInfo.getChildRate()*userIdInfoReqVo.getChildNums()) ;
			totalfee = totalfee +fee;
		}
		ticketOrder.setTicketNums(userIdInfoVo.size()+ticketNum);
		ticketOrder.setReceiverName(userIdInfoVo.get(0).getUserName());
		ticketOrder.setReceiverPhone(userIdInfoVo.get(0).getPhone());
		ticketOrder.setReceiverIdNumber(userIdInfoVo.get(0).getIdNumber());
		ticketOrder.setPayType(PayTypeEnum.Other_PAY.getKey());
		ticketOrder.setOrderNo(StringUtils.getRandomWithTimestamp(32));
		ticketOrder.setPayTime(new Date());
		ticketOrder.setNeedFee(totalfee);
		ticketOrder.setTotalFee(totalfee);
		ticketOrder.setStatus(PayStatusEnum.Payment_success.getKey());
		ticketOrder.setCreateTime(new Date());
		ticketOrder.setUpdateTime(new Date());
		ticketOrderDao.insert(ticketOrder);

		//拆订单，将订单详细信息存入 t_ticket_order_detail
		String checkCode = "";
		if (ticketInfo.getVerifyType() == TicketVerifyTypeEnum.More_Than_One_Ticket.getKey()) {//判断票的验票方式来生成验证号
			while (true) {
				checkCode = StringUtils.generateNumbers();
				FindRequestEntity findReq = new FindRequestEntity();
				findReq.addWhere("scenic_spot_id", WhereEnum.EQ,scenicSpotDetailVo.getId());
				findReq.addWhere("check_code", WhereEnum.EQ, checkCode);
				List<TicketOrderDetail> ticketOrderDetails = ticketOrderDetailDao.find(findReq);
				if (ticketOrderDetails == null || ticketOrderDetails.size() == 0) {
					break;
				}
			}
		}
		Date entryTime = DateTimeUtil.string2Date(DateTimeUtil.date2String(new Date(), "yyyy-MM-dd"), "yyyy-MM-dd");
		LogUtils.info(entryTime);
		Calendar cal = Calendar.getInstance();
		cal.setTime(entryTime);
		cal.add(Calendar.DATE, ticketInfo.getEffectiveTime());
		LogUtils.info(cal.getTime());
		for (UserIdInfoReqVo userIdInfo : userIdInfoVo) {
			TicketOrderDetail ticketOrderDetail = new TicketOrderDetail();
			ticketOrderDetail.setOrderId(ticketOrder.getId());
			ticketOrderDetail.setChannel(TicketChannelEnum.Scenic_spot_conductor.getKey());
			ticketOrderDetail.setUserId(bmsUser.getId());
			ticketOrderDetail.setTicketId(ticketOrder.getTicketId());
			ticketOrderDetail.setScenicSpotId(ticketOrder.getScenicSpotId());
			ticketOrderDetail.setUserName(userIdInfo.getUserName());
			ticketOrderDetail.setUserPhone(userIdInfo.getPhone());
			ticketOrderDetail.setUserIdType(UserIdNumberTypeEnum.identity.getKey());
			ticketOrderDetail.setUserIdNumber(userIdInfo.getIdNumber());
			if(userIdInfo.getBid() == null){
				FindRequestEntity findReq = new FindRequestEntity();
				findReq.addWhere("user_id_number", WhereEnum.EQ, userIdInfo.getIdNumber());
				findReq.addWhere("user_id_bid", WhereEnum.NE, "NULL");
				List<TicketOrderDetail> ticketOrderDetailList2 = ticketOrderDetailDao.find(findReq);
				if(ticketOrderDetailList2 != null && ticketOrderDetailList2.size() > 0){
					ticketOrderDetail.setUserIdBid(ticketOrderDetailList2.get(0).getUserIdBid());
				}
			}else {
				ticketOrderDetail.setUserIdBid(userIdInfo.getBid());
			}
			
			ticketOrderDetail.setUserIdBid(userIdInfo.getBid());
			ticketOrderDetail.setEntryTime(entryTime);
			ticketOrderDetail.setValidTime(cal.getTime());
			if (ticketInfo.getVerifyType() == TicketVerifyTypeEnum.More_Than_One_Ticket.getKey()) {
				ticketOrderDetail.setCheckCode(checkCode);
			} else {
				while (true) {
					checkCode = StringUtils.generateNumbers();

					FindRequestEntity findReq = new FindRequestEntity();
					findReq.addWhere("scenic_spot_id", WhereEnum.EQ,scenicSpotDetailVo.getId());
					findReq.addWhere("check_code", WhereEnum.EQ, checkCode);
					List<TicketOrderDetail> ticketOrderDetails = ticketOrderDetailDao.find(findReq);
					if (ticketOrderDetails == null || ticketOrderDetails.size() == 0) {
						break;
					}
				}
				ticketOrderDetail.setCheckCode(checkCode);
			}
			ticketOrderDetail.setStatus(UseTicketsStatusEnum.Already_paid.getKey());
			ticketOrderDetail.setCreateTime(new Date());
			ticketOrderDetail.setUpdateTime(new Date());
			ticketOrderDetailDao.insert(ticketOrderDetail);
			if(userIdInfo.getChildNums() != null){
				for (int i = 0; i < userIdInfo.getChildNums(); i++) {
					TicketOrderDetail ticketOrderDetailChild = new TicketOrderDetail();
					ticketOrderDetailChild.setOrderId(ticketOrder.getId());
					ticketOrderDetailChild.setChannel(TicketChannelEnum.Scenic_spot_conductor.getKey());
					ticketOrderDetailChild.setIsChild(1);
					ticketOrderDetailChild.setUserId(bmsUser.getId());
					ticketOrderDetailChild.setScenicSpotId(ticketOrder.getScenicSpotId());
					ticketOrderDetailChild.setTicketId(ticketOrder.getTicketId());
					ticketOrderDetailChild.setUserName(userIdInfo.getUserName());
					ticketOrderDetailChild.setUserPhone(userIdInfo.getPhone());
					ticketOrderDetailChild.setUserIdType(UserIdNumberTypeEnum.identity.getKey());
					ticketOrderDetailChild.setUserIdNumber(userIdInfo.getIdNumber());
					ticketOrderDetailChild.setUserIdBid(ticketOrderDetail.getUserIdBid());
					ticketOrderDetailChild.setEntryTime(entryTime);
					ticketOrderDetailChild.setValidTime(cal.getTime());
					if (ticketInfo.getVerifyType() == TicketVerifyTypeEnum.More_Than_One_Ticket.getKey()) {
						ticketOrderDetailChild.setCheckCode(checkCode);
					} else {
						while (true) {
							checkCode = StringUtils.generateNumbers();

							FindRequestEntity findReq = new FindRequestEntity();
							findReq.addWhere("check_code", WhereEnum.EQ, checkCode);
							List<TicketOrderDetail> ticketOrderDetails = ticketOrderDetailDao.find(findReq);
							if (ticketOrderDetails == null || ticketOrderDetails.size() == 0) {
								break;
							}
						}
						ticketOrderDetailChild.setCheckCode(checkCode);
					}
					ticketOrderDetailChild.setStatus(UseTicketsStatusEnum.Already_paid.getKey());
					ticketOrderDetailChild.setCreateTime(new Date());
					ticketOrderDetailChild.setUpdateTime(new Date());
					ticketOrderDetailDao.insert(ticketOrderDetailChild);
				}
			}
			
		}
		
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("order_id", WhereEnum.EQ, ticketOrder.getId());
		List<TicketOrderDetail> ticketOrderDetailList = ticketOrderDetailDao.find(findReq);
		List<TicketOrderDetailVo> ticketOrderDetailVoList = orderDetailToVoPC(ticketOrderDetailList);
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("ticketOrderDetailVoList", ticketOrderDetailVoList);
		resultMap.put("ticketOrder", ticketOrder);
		return resultMap;
	}

	@Override
	public Map<String, Object> activationTiecktsPC(String userIdInfoList, Integer ticketInfoId, BmsUser bmsUser)
			throws Exception {
		List< UserIdInfoReqVo> userIdInfoVo = JSONUtil.jsonToList(userIdInfoList, UserIdInfoReqVo.class);
		TicketInfo ticketInfo = ticketInfoDao.get(ticketInfoId);
		ScenicSpotDetailVo scenicSpotDetailVo = scenicSpotService.getScenicSpotDetail(ticketInfo.getScenicSpotId());
		TicketOrder ticketOrder = new TicketOrder();
		ticketOrder.setScenicSpotId(scenicSpotDetailVo.getId());
		ticketOrder.setChannel(TicketChannelEnum.Scenic_spot_conductor.getKey());
		ticketOrder.setUserId(bmsUser.getId());
		ticketOrder.setTicketId(ticketInfo.getId());
		Integer totalfee = 0;
		Integer ticketNum = 0;
		for (UserIdInfoReqVo userIdInfoReqVo : userIdInfoVo) {
			ticketNum = ticketNum +  userIdInfoReqVo.getChildNums();
			Integer fee =(int) (ticketInfo.getPrice() + ticketInfo.getPrice()*ticketInfo.getChildRate()*userIdInfoReqVo.getChildNums()) ;
			totalfee = totalfee +fee;
		}
		ticketOrder.setTicketNums(userIdInfoVo.size()+ticketNum);
		ticketOrder.setReceiverName(userIdInfoVo.get(0).getUserName());
		ticketOrder.setReceiverPhone(userIdInfoVo.get(0).getPhone());
		ticketOrder.setReceiverIdNumber(userIdInfoVo.get(0).getIdNumber());
		ticketOrder.setPayType(PayTypeEnum.Other_PAY.getKey());
		ticketOrder.setPayTime(new Date());
		ticketOrder.setOrderNo(StringUtils.getRandomWithTimestamp(32));
		ticketOrder.setNeedFee(totalfee);
		ticketOrder.setTotalFee(totalfee);
		ticketOrder.setStatus(PayStatusEnum.Payment_success.getKey());
		ticketOrder.setCreateTime(new Date());
		ticketOrder.setUpdateTime(new Date());
		ticketOrderDao.insert(ticketOrder);

		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("ticketOrder", ticketOrder);
		return resultMap;
	}

	@Override
	public Map<String, Object> bindingTiecktsPC(String userIdInfoStr, Integer ticketInfoId, BmsUser bmsUser, Integer orderId ,String checkCcode)
			throws Exception {
		Map<String, Object> resultMap = new HashMap<>();
		UserIdInfoReqVo userIdInfoVo = JSONUtil.toBean(userIdInfoStr, UserIdInfoReqVo.class);
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("check_code", WhereEnum.EQ, checkCcode);
		List<TicketOrderDetail> ticketOrderDetailList = ticketOrderDetailDao.find(findReq);
		if(ticketOrderDetailList != null && ticketOrderDetailList.size() >0 && StringUtils.isBank(ticketOrderDetailList.get(0).getUserIdNumber())){
			TicketOrderDetail ticketOrderDetail = ticketOrderDetailList.get(0);
			ticketOrderDetail.setOrderId(orderId);
			ticketOrderDetail.setChannel(TicketChannelEnum.Scenic_spot_conductor.getKey());
			if(userIdInfoVo.getChildNums() > 0){
				ticketOrderDetail.setIsChild(1);
			}
			ticketOrderDetail.setScenicSpotId(bmsUser.getScenicSpotId());
			ticketOrderDetail.setUserId(bmsUser.getId());
			ticketOrderDetail.setTicketId(ticketInfoId);
			ticketOrderDetail.setPrintStatus(PrintStatusEnum.Already_Printed.getKey());
			ticketOrderDetail.setStatus(UseTicketsStatusEnum.Already_paid.getKey());
			ticketOrderDetail.setUserName(userIdInfoVo.getUserName());
			ticketOrderDetail.setUserIdType(UserIdNumberTypeEnum.identity.getKey());
			ticketOrderDetail.setUserIdNumber(userIdInfoVo.getIdNumber());
			if(userIdInfoVo.getBid() == null){
				findReq = new FindRequestEntity();
				findReq.addWhere("user_id_number", WhereEnum.EQ, userIdInfoVo.getIdNumber());
				findReq.addWhere("user_id_bid", WhereEnum.NE, "NULL");
				List<TicketOrderDetail> ticketOrderDetailList2 = ticketOrderDetailDao.find(findReq);
				if(ticketOrderDetailList2 != null && ticketOrderDetailList2.size() > 0){
					ticketOrderDetail.setUserIdBid(ticketOrderDetailList2.get(0).getUserIdBid());
				}
			}else {
				ticketOrderDetail.setUserIdBid(userIdInfoVo.getBid());
			}
			
			
			TicketInfo ticketInfo = ticketInfoDao.get(ticketInfoId);
			Date entryTime = DateTimeUtil.string2Date(DateTimeUtil.date2String(new Date(), "yyyy-MM-dd"), "yyyy-MM-dd");
			LogUtils.info(entryTime);
			Calendar cal = Calendar.getInstance();
			cal.setTime(entryTime);
			cal.add(Calendar.DATE, ticketInfo.getEffectiveTime());
			LogUtils.info(cal.getTime());
			ticketOrderDetail.setEntryTime(entryTime);
			ticketOrderDetail.setValidTime(cal.getTime());
			ticketOrderDetail.setVerifyTimes(0);
			ticketOrderDetail.setUpdateTime(new Date());
			ticketOrderDetail.setCreateTime(new Date());
			ticketOrderDetailDao.update(ticketOrderDetail);
			resultMap.put("msg","已激活");
			return resultMap;
		}
		resultMap.put("result", false);
		resultMap.put("msg","无效票");
		return resultMap;
	}

	@Override
	public Page<TicketOrder> pageTicketOrder(OrderListReqVo req , BmsUser bmsUser) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		if(bmsUser.getType() == BmsUserTypeEnum.Scenic_spot_conductor.getKey()){
			findReq.addWhere("channel", WhereEnum.EQ, TicketChannelEnum.Scenic_spot_conductor.getKey());
			findReq.addWhere("user_id", WhereEnum.EQ, bmsUser.getId());
		}
		if(!StringUtils.isBank(req.getStartTime())){
			findReq.addWhere("create_time", WhereEnum.GE, req.getStartTime());
		}
		if(!StringUtils.isBank(req.getEndTime())){
			findReq.addWhere("create_time", WhereEnum.LE, req.getEndTime());
		}
		if(!StringUtils.isBank(req.getOrderNo())){
			findReq.addWhere("order_no", WhereEnum.EQ, req.getOrderNo());
		}
		if(!StringUtils.isBank(req.getTransactionId())){
			findReq.addWhere("transaction_id", WhereEnum.EQ, req.getTransactionId());
		}
		if (req.getScenicSpotId() != null && req.getScenicSpotId() != 0) {
			findReq.addWhere("scenic_spot_id", WhereEnum.EQ, req.getScenicSpotId());
		}
		if (req.getStatus() != null) {
			findReq.addWhere("status", WhereEnum.EQ, req.getStatus());
		}
		findReq.addWhere("status", WhereEnum.NE, PayStatusEnum.cancel_order.getKey());
		findReq.addOrder("create_time", OrderEnum.DESC);
		findReq.setPage(req.getPageNo(), req.getPageSize());
		Page<TicketOrder> ticketOrderPage = page(findReq);
		return ticketOrderPage;
	}

	@Override
	public Map<String, Object> findOrderDetails(Integer orderId) throws Exception{
		Map<String, Object> resultMap = new HashMap<>();
		TicketOrder ticketOrder = get(orderId);
		if(ticketOrder != null){
			FindRequestEntity findReq = new FindRequestEntity();
			findReq.addWhere("order_id" ,WhereEnum.EQ , ticketOrder.getId());
			List<TicketOrderDetail> ticketOrderDetailList = ticketOrderDetailDao.find(findReq);
			List<TicketOrderDetailRespVo> ticketOrderDetailRespVoList = new ArrayList<>();
			if(ticketOrderDetailList != null & ticketOrderDetailList.size() > 0){
				for (TicketOrderDetail ticketOrderDetail : ticketOrderDetailList) {
					TicketInfo ticketInfo = ticketInfoDao.get(ticketOrderDetail.getTicketId());
					TicketOrderDetailRespVo ticketOrderDetailRespVo = new TicketOrderDetailRespVo();
					BeanUtils.copyProperties(ticketOrderDetail, ticketOrderDetailRespVo);
					ticketOrderDetailRespVo.setPrices(ticketInfo.getPrice(),ticketInfo.getChildRate());
					ticketOrderDetailRespVo.setTicketName(ticketInfo.getName());
					ticketOrderDetailRespVoList.add(ticketOrderDetailRespVo);
				}
				resultMap.put("ticketOrder", ticketOrder);
				resultMap.put("ticketOrderDetailRespVoList", ticketOrderDetailRespVoList);
				return resultMap;
			}
		}
		return null;
	}

	@Override
	public Map<String, Object> statistics(OrderListReqVo req ,BmsUser bmsUser) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();
		FindRequestEntity findReq = new FindRequestEntity();
		if(bmsUser.getType() == BmsUserTypeEnum.Scenic_spot_conductor.getKey()){
			findReq.addWhere("channel", WhereEnum.EQ, TicketChannelEnum.Scenic_spot_conductor.getKey());
			findReq.addWhere("user_id", WhereEnum.EQ, bmsUser.getId());
		}
		if(!StringUtils.isBank(req.getStartTime())){
			findReq.addWhere("create_time", WhereEnum.GE, req.getStartTime());
		}
		if(!StringUtils.isBank(req.getEndTime())){
			findReq.addWhere("create_time", WhereEnum.LE, req.getEndTime());
		}
		findReq.addWhere("scenic_spot_id", WhereEnum.EQ, bmsUser.getScenicSpotId());
		findReq.addWhere("status", WhereEnum.EQ, PayStatusEnum.Payment_success.getKey());
		TicketOrder ticketOrder = ticketOrderDao.sellTickStatis(findReq.getWhereList());
		LogUtils.info(ticketOrder);
		resultMap.put("sellTick", ticketOrder);
		return resultMap;
	}

}
